package cn.huiyunche.base.service.interfaces.impl;

import cn.huiyunche.base.service.interfaces.TmsOrderValidationResultService;
import cn.huiyunche.base.service.mappers.TmsOrderValidationResultMapper;
import cn.huiyunche.base.service.model.TmsOrderValidationResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @FileName: cn.huiyunche.service.base.tms.interfaces.impl
 * @Description: Description
 * @author: Aaron
 * @date: 2016/11/2 上午10:37
 */
@Service
public class TmsOrderValidationResultServiceImpl implements TmsOrderValidationResultService {

    private static final Logger LOGGER = LoggerFactory.getLogger(TmsOrderValidationResultServiceImpl.class);

    @Autowired
    private TmsOrderValidationResultMapper tmsOrderValidationResultMapper;

    @Override
    public Long add(TmsOrderValidationResult validationResult) {
        LOGGER.info("add param : {}", validationResult);
        if (null == validationResult) {
            LOGGER.error("add param validationResult must not null");
            throw new IllegalArgumentException("TMS订单验证结果不能为空");
        }

        tmsOrderValidationResultMapper.insertSelective(validationResult);
        return validationResult.getId();
    }

    @Override
    public int update(Long validationResultId, String errorMsg) {
        LOGGER.info("TmsOrderValidationResultServiceImpl.update params : {}, {}", validationResultId, errorMsg);
        if (null == validationResultId) {
            LOGGER.error("update param validationResultId must not be null");
            throw new IllegalArgumentException("主键不能为空");
        }

        TmsOrderValidationResult validationResult = new TmsOrderValidationResult();
        validationResult.setId(validationResultId);
        validationResult.setMessage(errorMsg);

        return tmsOrderValidationResultMapper.updateByPrimaryKeySelective(validationResult);
    }
}
